package homework.no_1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * 1)查看指定URL的HTML源文档内容？
 * 提示：使用URL类和URLConnection类
 */
public class URLTest {

    public static void getUrlStr(String str){

        BufferedReader brd = null;
        try {
            URL url = new URL(str);
            URLConnection uc = url.openConnection();
            brd = new BufferedReader(new InputStreamReader(uc.getInputStream(), "utf-8"));

            String s = null;
            while ((s = brd.readLine()) != null){
                System.out.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (brd != null){
                try {
                    brd.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        getUrlStr("https://www.jd.com/");
    }
}
